/*
 * @Description:
 * @Author: py
 * @Date: 2024-08-09
 */
import type { OptionsType } from 'plus-pro-components'

// import type { IDicts } from '../types'

export function useDicts() {
    const oOrderStatus = {
        0: '待付款',
        1: '待发货',
        2: '待收货',
        3: '已完成',
        4: '已关闭',
    }
    const oAfterSaleStatus = {
        1: '无售后/取消售后',
        2: '售后处理中',
        3: '退款中',
        4: '退款成功',
    }
    const oPayType = {
        'Alipay 2.0': '支付宝',
        'POS': 'POS消费',
        'UnionPay': '云闪付',
        'WXPay': '微信',
    }
    const dicts = {
        oAfterSaleStatus,
        oOrderStatus,
        oPayType,
    }

    const getDictLabel = (mapKey: string, dicKey: number | string) => {
        if (mapKey in dicts) {
            return dicts[mapKey][dicKey]
        }
        else {
            return ''
        }
    }

    const getDictOptions = (mapKey: string, hasAll: boolean = false) => {
        if (mapKey in dicts) {
            const targetMap = dicts[mapKey]
            const dictOptions = Object.entries(targetMap).map(([key, val]) => ({
                label: val,
                value: key,
            }))
            if (hasAll) {
                dictOptions.unshift({
                    label: '全部',
                    value: '',
                })
            }
            return dictOptions as OptionsType
        }
        else {
            return []
        }
    }

    return { getDictLabel, getDictOptions }
}
